package com.controller;

import com.controller.vo.ResultVO;
import com.entity.Coupon;
import com.github.pagehelper.PageInfo;
import com.service.CouponService;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CouponController
 * @Description TODO
 * @Author Kx
 * @Date 2025/5/28 19:35
 * @Version 1.0
 */
@RestController
public class CouponController extends BaseController {
    private final CouponService couponService;

    public CouponController(CouponService couponService) {
        this.couponService = couponService;
    }

    /**
     * @author: kx
     * @date: 2025/5/28 19:36
     * @param coupon : 优惠券信息
     * @return com.controller.vo.ResultVO<java.lang.String>
     * @description: 添加优惠券信息
    */
    @PostMapping("/coupon/addCoupon")
    public ResultVO<String> addCoupon(@RequestBody Coupon coupon) {
        couponService.addCoupon(coupon);
        return success("添加成功");
    }

    /**
     * @param coupon : 优惠券信息
     * @return com.controller.vo.ResultVO<java.lang.String>
     * @author: kx
     * @date: 2025/5/28 20:08
     * @description: 修改优惠券信息
     */
    @PostMapping("/coupon/updateCoupon")
    public ResultVO<String> updateCoupon(@RequestBody Coupon coupon) {
        couponService.updateCoupon(coupon);
        return success("修改成功");
    }

    /**
     * @author: kx
     * @date: 2025/6/19 11:59
     * @param pageNum : 页码
     * @param pageSize : 每页显示数量
     * @return com.controller.vo.ResultVO<com.github.pagehelper.PageInfo<com.entity.Coupon>>
     * @description: 分页查询优惠券信息
    */
    @GetMapping("/coupon/getPagedCoupons")
    public ResultVO<PageInfo<Coupon>> getPagedCoupons(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        return success(couponService.getPagedCoupons(pageNum, pageSize));
    }
}
